﻿using System;
using System.ComponentModel;
using System.Web.UI;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.Core;
using System.Web;

namespace Yuanlin.Business
{
    public class MyCompanyAnonymousInfo : YuanlinUserControl,
        IReplyConverter<AnonymousVisitCompanyReply, GetListOperation>
    {
        protected Repeater list;
        protected Pager pager;
        protected CurrentPage currentPage;
        private EntityList anonymousVisitCompanys;
        private int entityId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.AnonymousVisitCompanyId);
        private int categoryId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CategoryId);
        private string tradeType = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.TradeType);

        public override void GetRequests(List<BaseRequestBinder> requestBinders)
        {
            requestBinders.Add(RequestHelper.BuildGetAnonymousVisitCompanyListRequest(this, UserIdFromGreenNum, entityId, categoryId, tradeType == null ? "-1" : tradeType, pager.PageIndex, pager.PageSize));
        }


        private void BindData()
        {
            if (list == null)
            {
                return;
            }

            list.DataSource = anonymousVisitCompanys;
            list.DataBind();

            if (pager != null && currentPage != null)
            {
                pager.TotalPages = pager.CalculateTotalPages(anonymousVisitCompanys.TotalCount);
                currentPage.TotalRecords = (anonymousVisitCompanys.TotalCount);
                currentPage.TotalPages = pager.TotalPages;
                currentPage.PageIndex = pager.PageIndex;
            }
        }


        #region IReplyConverter<AnonymousVisitCompanyReply,GetListOperation> Members

        public void ConvertReply(AnonymousVisitCompanyReply reply, GetListOperation operation)
        {
            if (reply != null)
            {
                anonymousVisitCompanys = reply.EntityList;

                if (!Page.IsPostBack)
                {
                    BindData();
                }
            }
        }

        #endregion
    }
}
